package initialize

import (
	"github.com/gin-gonic/gin"
	"net/http"
	v1 "perfect-admin/api/v1"
	"perfect-admin/global"
	"perfect-admin/middleware"
	"perfect-admin/routers"
)

func SetupRouters() (Router *gin.Engine) {
	//Router = gin.Default()
	Router = gin.New()

	Router.Use(middleware.Cors(), middleware.Logger(), gin.Recovery())
	global.LOG.Info("use middleware cors logger recovery")

	Router.Static("/static", "static")
	Router.LoadHTMLGlob("templates/*")
	Router.GET("/", func(c *gin.Context) {
		c.HTML(http.StatusOK, "index.html", nil)
	})

	ApiV1Group := Router.Group("api/v1")
	// 用户登录
	ApiV1Group.POST("login", v1.Login)
	ApiV1Group.POST("logout", middleware.JWTAuth(), v1.LogOut)

	routers.InitBaseRouter(ApiV1Group)
	routers.InitUserRouter(ApiV1Group)
	routers.InitRoleRouter(ApiV1Group)
	routers.InitMenuRouter(ApiV1Group)
	routers.InitExcelRouter(ApiV1Group)
	routers.InitApiRouter(ApiV1Group)
	routers.InitCasbinRouter(ApiV1Group)
	routers.InitFileRouter(ApiV1Group)
	routers.InitMessageRouter(ApiV1Group)
	routers.InitLoginLogRouter(ApiV1Group)
	routers.InitOperLogRouter(ApiV1Group)

	global.LOG.Info("routers register success")

	return
}